
goog.require('goog.dom');
goog.require('goog.ui.Container');
goog.require('goog.ui.RoundedPanel');
goog.require('goog.ui.Component');
goog.require('goog.ui.Control');
goog.require('goog.ui.Toolbar');


var Widget = Class.create({
	initialize : function(){
//		this.titlePanel ="";
//		this.headPanel ="";
//		this.bodyPanel ="";
//		this.footPanel = "";
		this.title ="widget";
		this.height = 300;
		this.headerHeight = this.height/8;
		
		this.footerHeight = this.height/8;
		
		this.bodyHeight = this.height - this.headerHeight - this.footerHeight+"px";
		this.headerHeight = this.headerHeight +"px";
		this.footerHeight = this.footerHeight +"px";
		this.headerBackground = "#75684D";
		this.bodyBackground = "#65684D";
		this.footerBackground = "#75684D";
		this.border = "5px solid #d5d5d5";
		this.padding ="0px"
		this.isWidget = true;
		this.bodyOrientation = "goog.ui.Container.Orientation.HORIZONTAL";
		this.parentContainerElement=null;
		
	},
	
	init: function(o){
		/*set widget title*/
		this.title = o[DataConstants.TITLE];
		
		/*get parent element id*/
		o[DomConstants.PARENT_ELEMENT_ID]!=null?this.parentContainerElement = o[DomConstants.PARENT_ELEMENT_ID]:this.parentContainerElement =null;
		
		/*get body element id name*/
		o[DomConstants.WIDGET_BODY_ELEMENT_ID]!=null?this.bodyPabelName = o[DomConstants.WIDGET_BODY_ELEMENT_ID]:this.bodyPabelName =WidgetConstant.BODY_PANEL;
		
		o[WidgetConstant.WIDGET_TYPE]!=null?this.widgetType = o[WidgetConstant.WIDGET_TYPE]:this.widgetType = "0";
		
		o[WidgetConstant.IS_WIDGET]!=null?this.isWidget = o[WidgetConstant.IS_WIDGET]:this.isWidget = true;
		if(o[WidgetConstant.BORDER]!=null){
			this.border = o[WidgetConstant.BORDER];
		}
		if(o[WidgetConstant.HEAD_BACKGROUND]!=null){
			this.headerBackground = o[WidgetConstant.HEAD_BACKGROUND];
		}
		if(o[WidgetConstant.BODY_BACKGROUND]!=null){
			this.bodyBackground = o[WidgetConstant.BODY_BACKGROUND];
		}
		
		if(o[WidgetConstant.FOOT_BACKGROUND]!=null){
			this.footerBackground = o[WidgetConstant.FOOT_BACKGROUND];
		}
		
		/*initialize the main container for widget, it will hold all the components/controls*/
		this.widgetContainer = new goog.ui.Container();
		
		/*render the widget to parent element*/
		if(this.parentContainerElement != null){
			this.widgetContainer.render(goog.dom.$(this.parentContainerElement));
		}
		
		/*calculate width/height for head,body and foot of the widget*/
		this.height = o[DataConstants.HEIGHT];
		if(o[DataConstants.HEIGHT] == null){
			this.height = goog.dom.$(this.parentContainerElement).style.height.replace("px","");
		}
//		this.widgetContainer.getContentElement().style.height = this.height +"px";
//		this.headerHeight = this.height/10;
//		if(this.headerHeight<=20) this.headerHeight = 25;
//		this.footerHeight = this.height/10;
//		if(this.footerHeight<=20) this.headerHeight = 25;
		this.calculateHeaderZone();
		this.calculateFootZone();
		this.bodyHeight = this.height - this.headerHeight - this.footerHeight+"px";
		this.headerHeight = this.headerHeight +"px";
		this.footerHeight = this.footerHeight +"px";
		
		if(this.isWidget)this.initTitlePanel();
		
		this.initHeadPanel();
		this.initBodyPanel();
		this.initFootPanel();
		
		this.widgetContainer.getContentElement().style.border = this.border;
		this.widgetContainer.getContentElement().style.padding = this.padding;
		

	},
	
	calculateHeaderZone: function() {
		if(this.widgetType == WidgetConstant.HEAD_BODY_WIDGET || this.widgetType ==0){
			this.headerHeight = this.height/8;
			if(this.headerHeight<=20) this.headerHeight = 25;
		}else{
			this.headerHeight = 0;
		}
	},
	calculateFootZone: function() {
		if(this.widgetType == WidgetConstant.FOOT_BODY_WIDGET || this.widgetType ==0){
			this.footerHeight = this.height/8;
			if(this.footerHeight<=20) this.headerHeight = 25;
		}else{
			this.footerHeight = 0;
		}
	},
	getWidgetContent : function(){
		return this.widgetContainer.getContentElement();
	},
	
	getTitlePanel : function(){
		return this.titlePanel.getContentElement();
	},
	
	getHeaderPanel : function(){
		return this.headerPanel.getContentElement();
	},
	
	getBodyPanel : function(){
		return this.bodyPanel;//.getContentElement();
	},
	
	getFooterPanel : function(){
		return this.footerPanel.getContentElement();
	},
	
	initTitlePanel: function() {
		this.toolbar = new goog.ui.Toolbar();
//		this.titleTxt  = goog.dom.createDom('span', {'id':DomConstants.SPN_USER_INFO},this.title);
		this.titleCntr = new goog.ui.Control(this.title);
		this.toolbar.addChild(this.titleCntr,true);
//		this.toolbar.getContentElement().style.border = "1px solid";
		this.toolbar.getContentElement().style.width = "100%";
		this.toolbar.getContentElement().style.height = "20px";
		this.toolbar.getContentElement().style.padding = this.padding;
		this.toolbar.render(this.widgetContainer.getContentElement());
////		this.title.decorateInternal(this.titleTxt);
////		this.titleTxt = goog.dom.createDom('div', {'class':'goog-roundedpanel-content','style':'border:2px solid blue;width:200px','id':DomConstants.HEADER_ICON_PANEL},'');
//		this.titlePanelElement = goog.dom.createDom('div', {'id':'111','style':'border:2px solid green;'},this.titleTxt);
//		//var roundedPanelNode = goog.dom.getElement('roundedPanel');
//		this.titlePaneld = goog.ui.RoundedPanel.create(15,
//                20,
//                "#fedcba",
//                "#abcdef",
//                15);
////
//		this.titlePaneld.decorateInternal(this.titlePanelElement);
//		this.widgetContainer.decorateInternal(this.titlePanelElement);
//		
	},
	
	
//	
	initHeadPanel: function() {
		this.headerPanelElement = goog.dom.createDom('div', {'id':WidgetConstant.HEAD_PANEL},"");
		this.headerPanelElement.style.background = this.headerBackground;
//		this.headerPanelElement.style.border = "1px solid";
		this.headerPanelElement.style.height = this.headerHeight;
		this.headerPanelElement.style.width = "100%";
		this.headerPanelElement.style.padding = this.padding;
		this.headerPanel = new goog.ui.Control(this.headerPanelElement);
//		this.headerPanel.style.backgoundColor = this.headerBackground;
		this.widgetContainer.addChild(this.headerPanel, true);
//		this.headerPanelElement.style.border = "1px solid";
		
	},
	initBodyPanel: function() {
		this.bodyPanelElement = goog.dom.createDom('div', {'id':this.bodyPabelName},"");
		this.bodyPanelElement.style.background = this.bodyBackground;
//		this.bodyPanelElement.style.border = this.border;
		this.bodyPanelElement.style.height = this.bodyHeight;
		this.bodyPanelElement.style.width = "100%";
//		this.bodyPanelElement.style.padding = this.padding;
		this.bodyPanelElement.style.paddingBottom = "7px";
//		this.bodyPanel11 = new goog.ui.Container();
//		this.bodyPanel11.setOrientation(goog.ui.Container.Orientation.HORIZONTAL);
//		this.bodyPanel11.decorateInternal(this.bodyPanelElement);
		this.bodyPanel = new goog.ui.Control(this.bodyPanelElement);
//		this.bodyPanel = new goog.ui.Container();
//		this.bodyPanel.decorateInternal(this.bodyPanelElement);
		this.widgetContainer.addChild(this.bodyPanel, true);
	},
	initFootPanel: function() {
		this.footerPanelElement = goog.dom.createDom('div', {'id':WidgetConstant.FOOT_PANEL},"");
		this.footerPanelElement.style.background = this.footerBackground;
//		this.footerPanelElement.style.border = "1px solid";
		this.footerPanelElement.style.height = this.footerHeight;
		this.footerPanelElement.style.width = "100%";
		this.headerPanelElement.style.padding = this.padding;
		this.footerPanel = new goog.ui.Control(this.footerPanelElement);
		this.widgetContainer.addChild(this.footerPanel, true);
	}
});